home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / a2.0bemacs-src.lha / Emacs-19.25 / lib-src / getdate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-11  |  48.2 KB  |  1,945 lines

  1.  
  2. /*  A Bison parser, made from getdate.y  */
  3.  
  4. #define YYBISON 1  /* Identify Bison output.  */
  5.  
  6. #define    tAGO    258
  7. #define    tDAY    259
  8. #define    tDAYZONE    260
  9. #define    tID    261
  10. #define    tMERIDIAN    262
  11. #define    tMINUTE_UNIT    263
  12. #define    tMONTH    264
  13. #define    tMONTH_UNIT    265
  14. #define    tSEC_UNIT    266
  15. #define    tSNUMBER    267
  16. #define    tUNUMBER    268
  17. #define    tZONE    269
  18. #define    tDST    270
  19.  
  20. #line 1 "getdate.y"
  21.  
  22. /*
  23. **  Originally written by Steven M. Bellovin <smb@research.att.com> while
  24. **  at the University of North Carolina at Chapel Hill.  Later tweaked by
  25. **  a couple of people on Usenet.  Completely overhauled by Rich $alz
  26. **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
  27. **  send any email to Rich.
  28. **
  29. **  This grammar has nine shift/reduce conflicts.
  30. **
  31. **  This code is in the public domain and has no copyright.
  32. */
  33. /* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */
  34. /* SUPPRESS 288 on yyerrlab *//* Label unused */
  35.  
  36. #ifdef HAVE_CONFIG_H
  37. #if defined (emacs) || defined (CONFIG_BROKETS)
  38. #include <config.h>
  39. #else
  40. #include "config.h"
  41. #endif
  42. #endif
  43.  
  44. /* Since the code of getdate.y is not included in the Emacs executable
  45.    itself, there is no need to #define static in this file.  Even if
  46.    the code were included in the Emacs executable, it probably
  47.    wouldn't do any harm to #undef it here; this will only cause
  48.    problems if we try to write to a static variable, which I don't
  49.    think this code needs to do.  */
  50. #ifdef emacs
  51. #undef static
  52. #endif
  53.  
  54. /* The following block of alloca-related preprocessor directives is here
  55.    solely to allow compilation by non GNU-C compilers of the C parser
  56.    produced from this file by old versions of bison.  Newer versions of
  57.    bison include a block similar to this one in bison.simple.  */
  58.    
  59. #ifdef __GNUC__
  60. #define alloca __builtin_alloca
  61. #else
  62. #ifdef HAVE_ALLOCA_H
  63. #include <alloca.h>
  64. #else
  65. #ifdef _AIX
  66.  #pragma alloca
  67. #else
  68. void *alloca ();
  69. #endif
  70. #endif
  71. #endif
  72.  
  73. #ifdef __GNUC__
  74. #undef alloca
  75. #define alloca __builtin_alloca
  76. #else
  77. #ifdef HAVE_ALLOCA_H
  78. #include <alloca.h>
  79. #else
  80. #ifdef _AIX /* for Bison */
  81.  #pragma alloca
  82. #else
  83. void *alloca ();
  84. #endif
  85. #endif
  86. #endif
  87.  
  88. #include <stdio.h>
  89. #include <ctype.h>
  90.  
  91. /* The code at the top of get_date which figures out the offset of the
  92.    current time zone checks various CPP symbols to see if special
  93.    tricks are need, but defaults to using the gettimeofday system call.
  94.    Include <sys/time.h> if that will be used.  */
  95.  
  96. #if    defined(vms)
  97.  
  98. #include <types.h>
  99. #include <time.h>
  100.  
  101. #else
  102.  
  103. #include <sys/types.h>
  104.  
  105. #ifdef TIME_WITH_SYS_TIME
  106. #include <sys/time.h>
  107. #include <time.h>
  108. #else
  109. #ifdef HAVE_SYS_TIME_H
  110. #include <sys/time.h>
  111. #else
  112. #include <time.h>
  113. #endif
  114. #endif
  115.  
  116. #ifdef timezone
  117. #undef timezone /* needed for sgi */
  118. #endif
  119.  
  120. #if defined(HAVE_SYS_TIMEB_H)
  121. #include <sys/timeb.h>
  122. #else
  123. /*
  124. ** We use the obsolete `struct timeb' as part of our interface!
  125. ** Since the system doesn't have it, we define it here;
  126. ** our callers must do likewise.
  127. */
  128. struct timeb {
  129.     time_t        time;        /* Seconds since the epoch    */
  130.     unsigned short    millitm;    /* Field not used        */
  131.     short        timezone;    /* Minutes west of GMT        */
  132.     short        dstflag;    /* Field not used        */
  133. };
  134. #endif /* defined(HAVE_SYS_TIMEB_H) */
  135.  
  136. #endif    /* defined(vms) */
  137.  
  138. #if defined (STDC_HEADERS) || defined (USG)
  139. #include <string.h>
  140. #endif
  141.  
  142. /* Some old versions of bison generate parsers that use bcopy.
  143.    That loses on systems that don't provide the function, so we have
  144.    to redefine it here.  */
  145. #if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
  146. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  147. #endif
  148.  
  149. extern struct tm    *gmtime();
  150. extern struct tm    *localtime();
  151.  
  152. #define yyparse getdate_yyparse
  153. #define yylex getdate_yylex
  154. #define yyerror getdate_yyerror
  155.  
  156. static int yylex ();
  157. static int yyerror ();
  158.  
  159. #if    !defined(lint) && !defined(SABER)
  160. static char RCS[] =
  161.     "$Header: str2date.y,v 2.1 90/09/06 08:15:06 cronan Exp $";
  162. #endif    /* !defined(lint) && !defined(SABER) */
  163.  
  164.  
  165. #define EPOCH        1970
  166. #define HOUR(x)        ((time_t)(x) * 60)
  167. #define SECSPERDAY    (24L * 60L * 60L)
  168.  
  169.  
  170. /*
  171. **  An entry in the lexical lookup table.
  172. */
  173. typedef struct _TABLE {
  174.     char    *name;
  175.     int        type;
  176.     time_t    value;
  177. } TABLE;
  178.  
  179.  
  180. /*
  181. **  Daylight-savings mode:  on, off, or not yet known.
  182. */
  183. typedef enum _DSTMODE {
  184.     DSTon, DSToff, DSTmaybe
  185. } DSTMODE;
  186.  
  187. /*
  188. **  Meridian:  am, pm, or 24-hour style.
  189. */
  190. typedef enum _MERIDIAN {
  191.     MERam, MERpm, MER24
  192. } MERIDIAN;
  193.  
  194.  
  195. /*
  196. **  Global variables.  We could get rid of most of these by using a good
  197. **  union as the yacc stack.  (This routine was originally written before
  198. **  yacc had the %union construct.)  Maybe someday; right now we only use
  199. **  the %union very rarely.
  200. */
  201. static char    *yyInput;
  202. static DSTMODE    yyDSTmode;
  203. static time_t    yyDayOrdinal;
  204. static time_t    yyDayNumber;
  205. static int    yyHaveDate;
  206. static int    yyHaveDay;
  207. static int    yyHaveRel;
  208. static int    yyHaveTime;
  209. static int    yyHaveZone;
  210. static time_t    yyTimezone;
  211. static time_t    yyDay;
  212. static time_t    yyHour;
  213. static time_t    yyMinutes;
  214. static time_t    yyMonth;
  215. static time_t    yySeconds;
  216. static time_t    yyYear;
  217. static MERIDIAN    yyMeridian;
  218. static time_t    yyRelMonth;
  219. static time_t    yyRelSeconds;
  220.  
  221.  
  222. #line 203 "getdate.y"
  223. typedef union {
  224.     time_t        Number;
  225.     enum _MERIDIAN    Meridian;
  226. } YYSTYPE;
  227.  
  228. #ifndef YYLTYPE
  229. typedef
  230.   struct yyltype
  231.     {
  232.       int timestamp;
  233.       int first_line;
  234.       int first_column;
  235.       int last_line;
  236.       int last_column;
  237.       char *text;
  238.    }
  239.   yyltype;
  240.  
  241. #define YYLTYPE yyltype
  242. #endif
  243.  
  244. #include <stdio.h>
  245.  
  246. #ifndef __STDC__
  247. #define const
  248. #endif
  249.  
  250.  
  251.  
  252. #define    YYFINAL        51
  253. #define    YYFLAG        -32768
  254. #define    YYNTBASE    19
  255.  
  256. #define YYTRANSLATE(x) ((unsigned)(x) <= 270 ? yytranslate[x] : 29)
  257.  
  258. static const char yytranslate[] = {     0,
  259.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  260.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  261.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  262.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  263.      2,     2,     2,    17,     2,     2,    18,     2,     2,     2,
  264.      2,     2,     2,     2,     2,     2,     2,    16,     2,     2,
  265.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  266.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  267.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  268.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  269.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  270.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  271.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  272.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  273.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  274.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  275.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  276.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  277.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  278.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  279.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  280.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  281.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  282.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  283.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  284.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  285.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15
  286. };
  287.  
  288. static const short yyprhs[] = {     0,
  289.      0,     1,     4,     6,     8,    10,    12,    14,    16,    19,
  290.     24,    29,    36,    43,    45,    47,    50,    52,    55,    58,
  291.     62,    68,    72,    75,    80,    83,    87,    90,    92,    95,
  292.     98,   100,   103,   106,   108,   111,   114,   116,   118,   119
  293. };
  294.  
  295. static const short yyrhs[] = {    -1,
  296.     19,    20,     0,    21,     0,    22,     0,    24,     0,    23,
  297.      0,    25,     0,    27,     0,    13,     7,     0,    13,    16,
  298.     13,    28,     0,    13,    16,    13,    12,     0,    13,    16,
  299.     13,    16,    13,    28,     0,    13,    16,    13,    16,    13,
  300.     12,     0,    14,     0,     5,     0,    14,    15,     0,     4,
  301.      0,     4,    17,     0,    13,     4,     0,    13,    18,    13,
  302.      0,    13,    18,    13,    18,    13,     0,    13,    12,    12,
  303.      0,     9,    13,     0,     9,    13,    17,    13,     0,    13,
  304.      9,     0,    13,     9,    13,     0,    26,     3,     0,    26,
  305.      0,    13,     8,     0,    12,     8,     0,     8,     0,    12,
  306.     11,     0,    13,    11,     0,    11,     0,    12,    10,     0,
  307.     13,    10,     0,    10,     0,    13,     0,     0,     7,     0
  308. };
  309.  
  310. #if YYDEBUG != 0
  311. static const short yyrline[] = { 0,
  312.    217,   218,   221,   224,   227,   230,   233,   236,   239,   245,
  313.    251,   258,   264,   274,   278,   282,   289,   293,   297,   303,
  314.    307,   312,   318,   322,   327,   331,   338,   342,   345,   348,
  315.    351,   354,   357,   360,   363,   366,   369,   374,   402,   405
  316. };
  317.  
  318. static const char * const yytname[] = {   "$","error","$illegal.","tAGO","tDAY",
  319. "tDAYZONE","tID","tMERIDIAN","tMINUTE_UNIT","tMONTH","tMONTH_UNIT","tSEC_UNIT",
  320. "tSNUMBER","tUNUMBER","tZONE","tDST","':'","','","'/'","spec","item","time",
  321. "zone","day","date","rel","relunit","number","o_merid",""
  322. };
  323. #endif
  324.  
  325. static const short yyr1[] = {     0,
  326.     19,    19,    20,    20,    20,    20,    20,    20,    21,    21,
  327.     21,    21,    21,    22,    22,    22,    23,    23,    23,    24,
  328.     24,    24,    24,    24,    24,    24,    25,    25,    26,    26,
  329.     26,    26,    26,    26,    26,    26,    26,    27,    28,    28
  330. };
  331.  
  332. static const short yyr2[] = {     0,
  333.      0,     2,     1,     1,     1,     1,     1,     1,     2,     4,
  334.      4,     6,     6,     1,     1,     2,     1,     2,     2,     3,
  335.      5,     3,     2,     4,     2,     3,     2,     1,     2,     2,
  336.      1,     2,     2,     1,     2,     2,     1,     1,     0,     1
  337. };
  338.  
  339. static const short yydefact[] = {     1,
  340.      0,    17,    15,    31,     0,    37,    34,     0,    38,    14,
  341.      2,     3,     4,     6,     5,     7,    28,     8,    18,    23,
  342.     30,    35,    32,    19,     9,    29,    25,    36,    33,     0,
  343.      0,     0,    16,    27,     0,    26,    22,    39,    20,    24,
  344.     40,    11,     0,    10,     0,    39,    21,    13,    12,     0,
  345.      0
  346. };
  347.  
  348. static const short yydefgoto[] = {     1,
  349.     11,    12,    13,    14,    15,    16,    17,    18,    44
  350. };
  351.  
  352. static const short yypact[] = {-32768,
  353.      0,   -15,-32768,-32768,   -10,-32768,-32768,    25,    11,    -8,
  354. -32768,-32768,-32768,-32768,-32768,-32768,    13,-32768,-32768,     7,
  355. -32768,-32768,-32768,-32768,-32768,-32768,     4,-32768,-32768,    14,
  356.     15,    19,-32768,-32768,    24,-32768,-32768,    18,    20,-32768,
  357. -32768,-32768,    26,-32768,    27,    -6,-32768,-32768,-32768,    31,
  358. -32768
  359. };
  360.  
  361. static const short yypgoto[] = {-32768,
  362. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,    -5
  363. };
  364.  
  365.  
  366. #define    YYLAST        41
  367.  
  368.  
  369. static const short yytable[] = {    50,
  370.     41,    19,    20,     2,     3,    48,    33,     4,     5,     6,
  371.      7,     8,     9,    10,    24,    34,    36,    25,    26,    27,
  372.     28,    29,    30,    35,    41,    37,    31,    38,    32,    42,
  373.     51,    39,    21,    43,    22,    23,    40,    45,    46,    47,
  374.     49
  375. };
  376.  
  377. static const short yycheck[] = {     0,
  378.      7,    17,    13,     4,     5,    12,    15,     8,     9,    10,
  379.     11,    12,    13,    14,     4,     3,    13,     7,     8,     9,
  380.     10,    11,    12,    17,     7,    12,    16,    13,    18,    12,
  381.      0,    13,     8,    16,    10,    11,    13,    18,    13,    13,
  382.     46
  383. };
  384. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  385. #line 3 "bison.simple"
  386.  
  387. /* Skeleton output parser for bison,
  388.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  389.  
  390.    This program is free software; you can redistribute it and/or modify
  391.    it under the terms of the GNU General Public License as published by
  392.    the Free Software Foundation; either version 1, or (at your option)
  393.    any later version.
  394.  
  395.    This program is distributed in the hope that it will be useful,
  396.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  397.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  398.    GNU General Public License for more details.
  399.  
  400.    You should have received a copy of the GNU General Public License
  401.    along with this program; if not, write to the Free Software
  402.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  403.  
  404.  
  405. #ifndef alloca
  406. #ifdef __GNUC__
  407. #define alloca __builtin_alloca
  408. #else /* not GNU C.  */
  409. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
  410. #include <alloca.h>
  411. #else /* not sparc */
  412. #if defined (MSDOS) && !defined (__TURBOC__)
  413. #include <malloc.h>
  414. #else /* not MSDOS, or __TURBOC__ */
  415. #if defined(_AIX)
  416. #include <malloc.h>
  417.  #pragma alloca
  418. #else /* not MSDOS, __TURBOC__, or _AIX */
  419. #ifdef __hpux
  420. #ifdef __cplusplus
  421. extern "C" {
  422. void *alloca (unsigned int);
  423. };
  424. #else /* not __cplusplus */
  425. void *alloca ();
  426. #endif /* not __cplusplus */
  427. #endif /* __hpux */
  428. #endif /* not _AIX */
  429. #endif /* not MSDOS, or __TURBOC__ */
  430. #endif /* not sparc.  */
  431. #endif /* not GNU C.  */
  432. #endif /* alloca not defined.  */
  433.  
  434. /* This is the parser code that is written into each bison parser
  435.   when the %semantic_parser declaration is not specified in the grammar.
  436.   It was written by Richard Stallman by simplifying the hairy parser
  437.   used when %semantic_parser is specified.  */
  438.  
  439. /* Note: there must be only one dollar sign in this file.
  440.    It is replaced by the list of actions, each action
  441.    as one case of the switch.  */
  442.  
  443. #define yyerrok        (yyerrstatus = 0)
  444. #define yyclearin    (yychar = YYEMPTY)
  445. #define YYEMPTY        -2
  446. #define YYEOF        0
  447. #define YYACCEPT    return(0)
  448. #define YYABORT     return(1)
  449. #define YYERROR        goto yyerrlab1
  450. /* Like YYERROR except do call yyerror.
  451.    This remains here temporarily to ease the
  452.    transition to the new meaning of YYERROR, for GCC.
  453.    Once GCC version 2 has supplanted version 1, this can go.  */
  454. #define YYFAIL        goto yyerrlab
  455. #define YYRECOVERING()  (!!yyerrstatus)
  456. #define YYBACKUP(token, value) \
  457. do                                \
  458.   if (yychar == YYEMPTY && yylen == 1)                \
  459.     { yychar = (token), yylval = (value);            \
  460.       yychar1 = YYTRANSLATE (yychar);                \
  461.       YYPOPSTACK;                        \
  462.       goto yybackup;                        \
  463.     }                                \
  464.   else                                \
  465.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  466. while (0)
  467.  
  468. #define YYTERROR    1
  469. #define YYERRCODE    256
  470.  
  471. #ifndef YYPURE
  472. #define YYLEX        yylex()
  473. #endif
  474.  
  475. #ifdef YYPURE
  476. #ifdef YYLSP_NEEDED
  477. #define YYLEX        yylex(&yylval, &yylloc)
  478. #else
  479. #define YYLEX        yylex(&yylval)
  480. #endif
  481. #endif
  482.  
  483. /* If nonreentrant, generate the variables here */
  484.  
  485. #ifndef YYPURE
  486.  
  487. int    yychar;            /*  the lookahead symbol        */
  488. YYSTYPE    yylval;            /*  the semantic value of the        */
  489.                 /*  lookahead symbol            */
  490.  
  491. #ifdef YYLSP_NEEDED
  492. YYLTYPE yylloc;            /*  location data for the lookahead    */
  493.                 /*  symbol                */
  494. #endif
  495.  
  496. int yynerrs;            /*  number of parse errors so far       */
  497. #endif  /* not YYPURE */
  498.  
  499. #if YYDEBUG != 0
  500. int yydebug;            /*  nonzero means print parse trace    */
  501. /* Since this is uninitialized, it does not stop multiple parsers
  502.    from coexisting.  */
  503. #endif
  504.  
  505. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  506.  
  507. #ifndef    YYINITDEPTH
  508. #define YYINITDEPTH 200
  509. #endif
  510.  
  511. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  512.     (effective only if the built-in stack extension method is used).  */
  513.  
  514. #if YYMAXDEPTH == 0
  515. #undef YYMAXDEPTH
  516. #endif
  517.  
  518. #ifndef YYMAXDEPTH
  519. #define YYMAXDEPTH 10000
  520. #endif
  521.  
  522. /* Prevent warning if -Wstrict-prototypes.  */
  523. #ifdef __GNUC__
  524. int yyparse (void);
  525. #endif
  526.  
  527. #if __GNUC__ > 1        /* GNU C and GNU C++ define this.  */
  528. #define __yy_bcopy(FROM,TO,COUNT)    __builtin_memcpy(TO,FROM,COUNT)
  529. #else                /* not GNU C or C++ */
  530. #ifndef __cplusplus
  531.  
  532. /* This is the most reliable way to avoid incompatibilities
  533.    in available built-in functions on various systems.  */
  534. static void
  535. __yy_bcopy (from, to, count)
  536.      char *from;
  537.      char *to;
  538.      int count;
  539. {
  540.   register char *f = from;
  541.   register char *t = to;
  542.   register int i = count;
  543.  
  544.   while (i-- > 0)
  545.     *t++ = *f++;
  546. }
  547.  
  548. #else /* __cplusplus */
  549.  
  550. /* This is the most reliable way to avoid incompatibilities
  551.    in available built-in functions on various systems.  */
  552. static void
  553. __yy_bcopy (char *from, char *to, int count)
  554. {
  555.   register char *f = from;
  556.   register char *t = to;
  557.   register int i = count;
  558.  
  559.   while (i-- > 0)
  560.     *t++ = *f++;
  561. }
  562.  
  563. #endif
  564. #endif
  565.  
  566. #line 184 "bison.simple"
  567.  
  568. /* The user can define YYPARSE_PARAM as the name of an argument to be passed
  569.    into yyparse.  The argument should have type void *.
  570.    It should actually point to an object.
  571.    Grammar actions can access the variable by casting it
  572.    to the proper pointer type.  */
  573.  
  574. #ifdef YYPARSE_PARAM
  575. #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
  576. #else
  577. #define YYPARSE_PARAM
  578. #define YYPARSE_PARAM_DECL
  579. #endif
  580.  
  581. int
  582. yyparse(YYPARSE_PARAM)
  583.      YYPARSE_PARAM_DECL
  584. {
  585.   register int yystate;
  586.   register int yyn;
  587.   register short *yyssp;
  588.   register YYSTYPE *yyvsp;
  589.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  590.   int yychar1 = 0;        /*  lookahead token as an internal (translated) token number */
  591.  
  592.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  593.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  594.  
  595.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  596.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  597.  
  598. #ifdef YYLSP_NEEDED
  599.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  600.   YYLTYPE *yyls = yylsa;
  601.   YYLTYPE *yylsp;
  602.  
  603. #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
  604. #else
  605. #define YYPOPSTACK   (yyvsp--, yyssp--)
  606. #endif
  607.  
  608.   int yystacksize = YYINITDEPTH;
  609.  
  610. #ifdef YYPURE
  611.   int yychar;
  612.   YYSTYPE yylval;
  613.   int yynerrs;
  614. #ifdef YYLSP_NEEDED
  615.   YYLTYPE yylloc;
  616. #endif
  617. #endif
  618.  
  619.   YYSTYPE yyval;        /*  the variable used to return        */
  620.                 /*  semantic values from the action    */
  621.                 /*  routines                */
  622.  
  623.   int yylen;
  624.  
  625. #if YYDEBUG != 0
  626.   if (yydebug)
  627.     fprintf(stderr, "Starting parse\n");
  628. #endif
  629.  
  630.   yystate = 0;
  631.   yyerrstatus = 0;
  632.   yynerrs = 0;
  633.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  634.  
  635.   /* Initialize stack pointers.
  636.      Waste one element of value and location stack
  637.      so that they stay on the same level as the state stack.
  638.      The wasted elements are never initialized.  */
  639.  
  640.   yyssp = yyss - 1;
  641.   yyvsp = yyvs;
  642. #ifdef YYLSP_NEEDED
  643.   yylsp = yyls;
  644. #endif
  645.  
  646. /* Push a new state, which is found in  yystate  .  */
  647. /* In all cases, when you get here, the value and location stacks
  648.    have just been pushed. so pushing a state here evens the stacks.  */
  649. yynewstate:
  650.  
  651.   *++yyssp = yystate;
  652.  
  653.   if (yyssp >= yyss + yystacksize - 1)
  654.     {
  655.       /* Give user a chance to reallocate the stack */
  656.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  657.       YYSTYPE *yyvs1 = yyvs;
  658.       short *yyss1 = yyss;
  659. #ifdef YYLSP_NEEDED
  660.       YYLTYPE *yyls1 = yyls;
  661. #endif
  662.  
  663.       /* Get the current used size of the three stacks, in elements.  */
  664.       int size = yyssp - yyss + 1;
  665.  
  666. #ifdef yyoverflow
  667.       /* Each stack pointer address is followed by the size of
  668.      the data in use in that stack, in bytes.  */
  669. #ifdef YYLSP_NEEDED
  670.       /* This used to be a conditional around just the two extra args,
  671.      but that might be undefined if yyoverflow is a macro.  */
  672.       yyoverflow("parser stack overflow",
  673.          &yyss1, size * sizeof (*yyssp),
  674.          &yyvs1, size * sizeof (*yyvsp),
  675.          &yyls1, size * sizeof (*yylsp),
  676.          &yystacksize);
  677. #else
  678.       yyoverflow("parser stack overflow",
  679.          &yyss1, size * sizeof (*yyssp),
  680.          &yyvs1, size * sizeof (*yyvsp),
  681.          &yystacksize);
  682. #endif
  683.  
  684.       yyss = yyss1; yyvs = yyvs1;
  685. #ifdef YYLSP_NEEDED
  686.       yyls = yyls1;
  687. #endif
  688. #else /* no yyoverflow */
  689.       /* Extend the stack our own way.  */
  690.       if (yystacksize >= YYMAXDEPTH)
  691.     {
  692.       yyerror("parser stack overflow");
  693.       return 2;
  694.     }
  695.       yystacksize *= 2;
  696.       if (yystacksize > YYMAXDEPTH)
  697.     yystacksize = YYMAXDEPTH;
  698.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  699.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  700.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  701.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  702. #ifdef YYLSP_NEEDED
  703.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  704.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  705. #endif
  706. #endif /* no yyoverflow */
  707.  
  708.       yyssp = yyss + size - 1;
  709.       yyvsp = yyvs + size - 1;
  710. #ifdef YYLSP_NEEDED
  711.       yylsp = yyls + size - 1;
  712. #endif
  713.  
  714. #if YYDEBUG != 0
  715.       if (yydebug)
  716.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  717. #endif
  718.  
  719.       if (yyssp >= yyss + yystacksize - 1)
  720.     YYABORT;
  721.     }
  722.  
  723. #if YYDEBUG != 0
  724.   if (yydebug)
  725.     fprintf(stderr, "Entering state %d\n", yystate);
  726. #endif
  727.  
  728.   goto yybackup;
  729.  yybackup:
  730.  
  731. /* Do appropriate processing given the current state.  */
  732. /* Read a lookahead token if we need one and don't already have one.  */
  733. /* yyresume: */
  734.  
  735.   /* First try to decide what to do without reference to lookahead token.  */
  736.  
  737.   yyn = yypact[yystate];
  738.   if (yyn == YYFLAG)
  739.     goto yydefault;
  740.  
  741.   /* Not known => get a lookahead token if don't already have one.  */
  742.  
  743.   /* yychar is either YYEMPTY or YYEOF
  744.      or a valid token in external form.  */
  745.  
  746.   if (yychar == YYEMPTY)
  747.     {
  748. #if YYDEBUG != 0
  749.       if (yydebug)
  750.     fprintf(stderr, "Reading a token: ");
  751. #endif
  752.       yychar = YYLEX;
  753.     }
  754.  
  755.   /* Convert token to internal form (in yychar1) for indexing tables with */
  756.  
  757.   if (yychar <= 0)        /* This means end of input. */
  758.     {
  759.       yychar1 = 0;
  760.       yychar = YYEOF;        /* Don't call YYLEX any more */
  761.  
  762. #if YYDEBUG != 0
  763.       if (yydebug)
  764.     fprintf(stderr, "Now at end of input.\n");
  765. #endif
  766.     }
  767.   else
  768.     {
  769.       yychar1 = YYTRANSLATE(yychar);
  770.  
  771. #if YYDEBUG != 0
  772.       if (yydebug)
  773.     {
  774.       fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
  775.       /* Give the individual parser a way to print the precise meaning
  776.          of a token, for further debugging info.  */
  777. #ifdef YYPRINT
  778.       YYPRINT (stderr, yychar, yylval);
  779. #endif
  780.       fprintf (stderr, ")\n");
  781.     }
  782. #endif
  783.     }
  784.  
  785.   yyn += yychar1;
  786.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  787.     goto yydefault;
  788.  
  789.   yyn = yytable[yyn];
  790.  
  791.   /* yyn is what to do for this token type in this state.
  792.      Negative => reduce, -yyn is rule number.
  793.      Positive => shift, yyn is new state.
  794.        New state is final state => don't bother to shift,
  795.        just return success.
  796.      0, or most negative number => error.  */
  797.  
  798.   if (yyn < 0)
  799.     {
  800.       if (yyn == YYFLAG)
  801.     goto yyerrlab;
  802.       yyn = -yyn;
  803.       goto yyreduce;
  804.     }
  805.   else if (yyn == 0)
  806.     goto yyerrlab;
  807.  
  808.   if (yyn == YYFINAL)
  809.     YYACCEPT;
  810.  
  811.   /* Shift the lookahead token.  */
  812.  
  813. #if YYDEBUG != 0
  814.   if (yydebug)
  815.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  816. #endif
  817.  
  818.   /* Discard the token being shifted unless it is eof.  */
  819.   if (yychar != YYEOF)
  820.     yychar = YYEMPTY;
  821.  
  822.   *++yyvsp = yylval;
  823. #ifdef YYLSP_NEEDED
  824.   *++yylsp = yylloc;
  825. #endif
  826.  
  827.   /* count tokens shifted since error; after three, turn off error status.  */
  828.   if (yyerrstatus) yyerrstatus--;
  829.  
  830.   yystate = yyn;
  831.   goto yynewstate;
  832.  
  833. /* Do the default action for the current state.  */
  834. yydefault:
  835.  
  836.   yyn = yydefact[yystate];
  837.   if (yyn == 0)
  838.     goto yyerrlab;
  839.  
  840. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  841. yyreduce:
  842.   yylen = yyr2[yyn];
  843.   if (yylen > 0)
  844.     yyval = yyvsp[1-yylen]; /* implement default value of the action */
  845.  
  846. #if YYDEBUG != 0
  847.   if (yydebug)
  848.     {
  849.       int i;
  850.  
  851.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  852.            yyn, yyrline[yyn]);
  853.  
  854.       /* Print the symbols being reduced, and their result.  */
  855.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  856.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  857.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  858.     }
  859. #endif
  860.  
  861.  
  862.   switch (yyn) {
  863.  
  864. case 3:
  865. #line 221 "getdate.y"
  866. {
  867.         yyHaveTime++;
  868.     ;
  869.     break;}
  870. case 4:
  871. #line 224 "getdate.y"
  872. {
  873.         yyHaveZone++;
  874.     ;
  875.     break;}
  876. case 5:
  877. #line 227 "getdate.y"
  878. {
  879.         yyHaveDate++;
  880.     ;
  881.     break;}
  882. case 6:
  883. #line 230 "getdate.y"
  884. {
  885.         yyHaveDay++;
  886.     ;
  887.     break;}
  888. case 7:
  889. #line 233 "getdate.y"
  890. {
  891.         yyHaveRel++;
  892.     ;
  893.     break;}
  894. case 9:
  895. #line 239 "getdate.y"
  896. {
  897.         yyHour = yyvsp[-1].Number;
  898.         yyMinutes = 0;
  899.         yySeconds = 0;
  900.         yyMeridian = yyvsp[0].Meridian;
  901.     ;
  902.     break;}
  903. case 10:
  904. #line 245 "getdate.y"
  905. {
  906.         yyHour = yyvsp[-3].Number;
  907.         yyMinutes = yyvsp[-1].Number;
  908.         yySeconds = 0;
  909.         yyMeridian = yyvsp[0].Meridian;
  910.     ;
  911.     break;}
  912. case 11:
  913. #line 251 "getdate.y"
  914. {
  915.         yyHour = yyvsp[-3].Number;
  916.         yyMinutes = yyvsp[-1].Number;
  917.         yyMeridian = MER24;
  918.         yyDSTmode = DSToff;
  919.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  920.     ;
  921.     break;}
  922. case 12:
  923. #line 258 "getdate.y"
  924. {
  925.         yyHour = yyvsp[-5].Number;
  926.         yyMinutes = yyvsp[-3].Number;
  927.         yySeconds = yyvsp[-1].Number;
  928.         yyMeridian = yyvsp[0].Meridian;
  929.     ;
  930.     break;}
  931. case 13:
  932. #line 264 "getdate.y"
  933. {
  934.         yyHour = yyvsp[-5].Number;
  935.         yyMinutes = yyvsp[-3].Number;
  936.         yySeconds = yyvsp[-1].Number;
  937.         yyMeridian = MER24;
  938.         yyDSTmode = DSToff;
  939.         yyTimezone = - (yyvsp[0].Number % 100 + (yyvsp[0].Number / 100) * 60);
  940.     ;
  941.     break;}
  942. case 14:
  943. #line 274 "getdate.y"
  944. {
  945.         yyTimezone = yyvsp[0].Number;
  946.         yyDSTmode = DSToff;
  947.     ;
  948.     break;}
  949. case 15:
  950. #line 278 "getdate.y"
  951. {
  952.         yyTimezone = yyvsp[0].Number;
  953.         yyDSTmode = DSTon;
  954.     ;
  955.     break;}
  956. case 16:
  957. #line 283 "getdate.y"
  958. {
  959.         yyTimezone = yyvsp[-1].Number;
  960.         yyDSTmode = DSTon;
  961.     ;
  962.     break;}
  963. case 17:
  964. #line 289 "getdate.y"
  965. {
  966.         yyDayOrdinal = 1;
  967.         yyDayNumber = yyvsp[0].Number;
  968.     ;
  969.     break;}
  970. case 18:
  971. #line 293 "getdate.y"
  972. {
  973.         yyDayOrdinal = 1;
  974.         yyDayNumber = yyvsp[-1].Number;
  975.     ;
  976.     break;}
  977. case 19:
  978. #line 297 "getdate.y"
  979. {
  980.         yyDayOrdinal = yyvsp[-1].Number;
  981.         yyDayNumber = yyvsp[0].Number;
  982.     ;
  983.     break;}
  984. case 20:
  985. #line 303 "getdate.y"
  986. {
  987.         yyMonth = yyvsp[-2].Number;
  988.         yyDay = yyvsp[0].Number;
  989.     ;
  990.     break;}
  991. case 21:
  992. #line 307 "getdate.y"
  993. {
  994.         yyMonth = yyvsp[-4].Number;
  995.         yyDay = yyvsp[-2].Number;
  996.         yyYear = yyvsp[0].Number;
  997.     ;
  998.     break;}
  999. case 22:
  1000. #line 312 "getdate.y"
  1001. {
  1002.         /* ISO 8601 format.  yyyy-mm-dd.  */
  1003.         yyYear = yyvsp[-2].Number;
  1004.         yyMonth = -yyvsp[-1].Number;
  1005.         yyDay = -yyvsp[0].Number;
  1006.     ;
  1007.     break;}
  1008. case 23:
  1009. #line 318 "getdate.y"
  1010. {
  1011.         yyMonth = yyvsp[-1].Number;
  1012.         yyDay = yyvsp[0].Number;
  1013.     ;
  1014.     break;}
  1015. case 24:
  1016. #line 322 "getdate.y"
  1017. {
  1018.         yyMonth = yyvsp[-3].Number;
  1019.         yyDay = yyvsp[-2].Number;
  1020.         yyYear = yyvsp[0].Number;
  1021.     ;
  1022.     break;}
  1023. case 25:
  1024. #line 327 "getdate.y"
  1025. {
  1026.         yyMonth = yyvsp[0].Number;
  1027.         yyDay = yyvsp[-1].Number;
  1028.     ;
  1029.     break;}
  1030. case 26:
  1031. #line 331 "getdate.y"
  1032. {
  1033.         yyMonth = yyvsp[-1].Number;
  1034.         yyDay = yyvsp[-2].Number;
  1035.         yyYear = yyvsp[0].Number;
  1036.     ;
  1037.     break;}
  1038. case 27:
  1039. #line 338 "getdate.y"
  1040. {
  1041.         yyRelSeconds = -yyRelSeconds;
  1042.         yyRelMonth = -yyRelMonth;
  1043.     ;
  1044.     break;}
  1045. case 29:
  1046. #line 345 "getdate.y"
  1047. {
  1048.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  1049.     ;
  1050.     break;}
  1051. case 30:
  1052. #line 348 "getdate.y"
  1053. {
  1054.         yyRelSeconds += yyvsp[-1].Number * yyvsp[0].Number * 60L;
  1055.     ;
  1056.     break;}
  1057. case 31:
  1058. #line 351 "getdate.y"
  1059. {
  1060.         yyRelSeconds += yyvsp[0].Number * 60L;
  1061.     ;
  1062.     break;}
  1063. case 32:
  1064. #line 354 "getdate.y"
  1065. {
  1066.         yyRelSeconds += yyvsp[-1].Number;
  1067.     ;
  1068.     break;}
  1069. case 33:
  1070. #line 357 "getdate.y"
  1071. {
  1072.         yyRelSeconds += yyvsp[-1].Number;
  1073.     ;
  1074.     break;}
  1075. case 34:
  1076. #line 360 "getdate.y"
  1077. {
  1078.         yyRelSeconds++;
  1079.     ;
  1080.     break;}
  1081. case 35:
  1082. #line 363 "getdate.y"
  1083. {
  1084.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1085.     ;
  1086.     break;}
  1087. case 36:
  1088. #line 366 "getdate.y"
  1089. {
  1090.         yyRelMonth += yyvsp[-1].Number * yyvsp[0].Number;
  1091.     ;
  1092.     break;}
  1093. case 37:
  1094. #line 369 "getdate.y"
  1095. {
  1096.         yyRelMonth += yyvsp[0].Number;
  1097.     ;
  1098.     break;}
  1099. case 38:
  1100. #line 374 "getdate.y"
  1101. {
  1102.         if (yyHaveTime && yyHaveDate && !yyHaveRel)
  1103.         yyYear = yyvsp[0].Number;
  1104.         else {
  1105.         if(yyvsp[0].Number>10000) {
  1106.             time_t date_part;
  1107.  
  1108.             date_part= yyvsp[0].Number/10000;
  1109.             yyHaveDate++;
  1110.             yyDay= (date_part)%100;
  1111.             yyMonth= (date_part/100)%100;
  1112.             yyYear = date_part/10000;
  1113.         } 
  1114.             yyHaveTime++;
  1115.         if (yyvsp[0].Number < 100) {
  1116.             yyHour = yyvsp[0].Number;
  1117.             yyMinutes = 0;
  1118.         }
  1119.         else {
  1120.             yyHour = yyvsp[0].Number / 100;
  1121.             yyMinutes = yyvsp[0].Number % 100;
  1122.         }
  1123.         yySeconds = 0;
  1124.         yyMeridian = MER24;
  1125.         }
  1126.     ;
  1127.     break;}
  1128. case 39:
  1129. #line 402 "getdate.y"
  1130. {
  1131.         yyval.Meridian = MER24;
  1132.     ;
  1133.     break;}
  1134. case 40:
  1135. #line 405 "getdate.y"
  1136. {
  1137.         yyval.Meridian = yyvsp[0].Meridian;
  1138.     ;
  1139.     break;}
  1140. }
  1141.    /* the action file gets copied in in place of this dollarsign */
  1142. #line 480 "bison.simple"
  1143.  
  1144.   yyvsp -= yylen;
  1145.   yyssp -= yylen;
  1146. #ifdef YYLSP_NEEDED
  1147.   yylsp -= yylen;
  1148. #endif
  1149.  
  1150. #if YYDEBUG != 0
  1151.   if (yydebug)
  1152.     {
  1153.       short *ssp1 = yyss - 1;
  1154.       fprintf (stderr, "state stack now");
  1155.       while (ssp1 != yyssp)
  1156.     fprintf (stderr, " %d", *++ssp1);
  1157.       fprintf (stderr, "\n");
  1158.     }
  1159. #endif
  1160.  
  1161.   *++yyvsp = yyval;
  1162.  
  1163. #ifdef YYLSP_NEEDED
  1164.   yylsp++;
  1165.   if (yylen == 0)
  1166.     {
  1167.       yylsp->first_line = yylloc.first_line;
  1168.       yylsp->first_column = yylloc.first_column;
  1169.       yylsp->last_line = (yylsp-1)->last_line;
  1170.       yylsp->last_column = (yylsp-1)->last_column;
  1171.       yylsp->text = 0;
  1172.     }
  1173.   else
  1174.     {
  1175.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1176.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1177.     }
  1178. #endif
  1179.  
  1180.   /* Now "shift" the result of the reduction.
  1181.      Determine what state that goes to,
  1182.      based on the state we popped back to
  1183.      and the rule number reduced by.  */
  1184.  
  1185.   yyn = yyr1[yyn];
  1186.  
  1187.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1188.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1189.     yystate = yytable[yystate];
  1190.   else
  1191.     yystate = yydefgoto[yyn - YYNTBASE];
  1192.  
  1193.   goto yynewstate;
  1194.  
  1195. yyerrlab:   /* here on detecting error */
  1196.  
  1197.   if (! yyerrstatus)
  1198.     /* If not already recovering from an error, report this error.  */
  1199.     {
  1200.       ++yynerrs;
  1201.  
  1202. #ifdef YYERROR_VERBOSE
  1203.       yyn = yypact[yystate];
  1204.  
  1205.       if (yyn > YYFLAG && yyn < YYLAST)
  1206.     {
  1207.       int size = 0;
  1208.       char *msg;
  1209.       int x, count;
  1210.  
  1211.       count = 0;
  1212.       /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
  1213.       for (x = (yyn < 0 ? -yyn : 0);
  1214.            x < (sizeof(yytname) / sizeof(char *)); x++)
  1215.         if (yycheck[x + yyn] == x)
  1216.           size += strlen(yytname[x]) + 15, count++;
  1217.       msg = (char *) malloc(size + 15);
  1218.       if (msg != 0)
  1219.         {
  1220.           strcpy(msg, "parse error");
  1221.  
  1222.           if (count < 5)
  1223.         {
  1224.           count = 0;
  1225.           for (x = (yyn < 0 ? -yyn : 0);
  1226.                x < (sizeof(yytname) / sizeof(char *)); x++)
  1227.             if (yycheck[x + yyn] == x)
  1228.               {
  1229.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1230.             strcat(msg, yytname[x]);
  1231.             strcat(msg, "'");
  1232.             count++;
  1233.               }
  1234.         }
  1235.           yyerror(msg);
  1236.           free(msg);
  1237.         }
  1238.       else
  1239.         yyerror ("parse error; also virtual memory exceeded");
  1240.     }
  1241.       else
  1242. #endif /* YYERROR_VERBOSE */
  1243.     yyerror("parse error");
  1244.     }
  1245.  
  1246.   goto yyerrlab1;
  1247. yyerrlab1:   /* here on error raised explicitly by an action */
  1248.  
  1249.   if (yyerrstatus == 3)
  1250.     {
  1251.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1252.  
  1253.       /* return failure if at end of input */
  1254.       if (yychar == YYEOF)
  1255.     YYABORT;
  1256.  
  1257. #if YYDEBUG != 0
  1258.       if (yydebug)
  1259.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1260. #endif
  1261.  
  1262.       yychar = YYEMPTY;
  1263.     }
  1264.  
  1265.   /* Else will try to reuse lookahead token
  1266.      after shifting the error token.  */
  1267.  
  1268.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1269.  
  1270.   goto yyerrhandle;
  1271.  
  1272. yyerrdefault:  /* current state does not do anything special for the error token. */
  1273.  
  1274. #if 0
  1275.   /* This is wrong; only states that explicitly want error tokens
  1276.      should shift them.  */
  1277.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1278.   if (yyn) goto yydefault;
  1279. #endif
  1280.  
  1281. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1282.  
  1283.   if (yyssp == yyss) YYABORT;
  1284.   yyvsp--;
  1285.   yystate = *--yyssp;
  1286. #ifdef YYLSP_NEEDED
  1287.   yylsp--;
  1288. #endif
  1289.  
  1290. #if YYDEBUG != 0
  1291.   if (yydebug)
  1292.     {
  1293.       short *ssp1 = yyss - 1;
  1294.       fprintf (stderr, "Error: state stack now");
  1295.       while (ssp1 != yyssp)
  1296.     fprintf (stderr, " %d", *++ssp1);
  1297.       fprintf (stderr, "\n");
  1298.     }
  1299. #endif
  1300.  
  1301. yyerrhandle:
  1302.  
  1303.   yyn = yypact[yystate];
  1304.   if (yyn == YYFLAG)
  1305.     goto yyerrdefault;
  1306.  
  1307.   yyn += YYTERROR;
  1308.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1309.     goto yyerrdefault;
  1310.  
  1311.   yyn = yytable[yyn];
  1312.   if (yyn < 0)
  1313.     {
  1314.       if (yyn == YYFLAG)
  1315.     goto yyerrpop;
  1316.       yyn = -yyn;
  1317.       goto yyreduce;
  1318.     }
  1319.   else if (yyn == 0)
  1320.     goto yyerrpop;
  1321.  
  1322.   if (yyn == YYFINAL)
  1323.     YYACCEPT;
  1324.  
  1325. #if YYDEBUG != 0
  1326.   if (yydebug)
  1327.     fprintf(stderr, "Shifting error token, ");
  1328. #endif
  1329.  
  1330.   *++yyvsp = yylval;
  1331. #ifdef YYLSP_NEEDED
  1332.   *++yylsp = yylloc;
  1333. #endif
  1334.  
  1335.   yystate = yyn;
  1336.   goto yynewstate;
  1337. }
  1338. #line 410 "getdate.y"
  1339.  
  1340.  
  1341. /* Month and day table. */
  1342. static TABLE const MonthDayTable[] = {
  1343.     { "january",    tMONTH,  1 },
  1344.     { "february",    tMONTH,  2 },
  1345.     { "march",        tMONTH,  3 },
  1346.     { "april",        tMONTH,  4 },
  1347.     { "may",        tMONTH,  5 },
  1348.     { "june",        tMONTH,  6 },
  1349.     { "july",        tMONTH,  7 },
  1350.     { "august",        tMONTH,  8 },
  1351.     { "september",    tMONTH,  9 },
  1352.     { "sept",        tMONTH,  9 },
  1353.     { "october",    tMONTH, 10 },
  1354.     { "november",    tMONTH, 11 },
  1355.     { "december",    tMONTH, 12 },
  1356.     { "sunday",        tDAY, 0 },
  1357.     { "monday",        tDAY, 1 },
  1358.     { "tuesday",    tDAY, 2 },
  1359.     { "tues",        tDAY, 2 },
  1360.     { "wednesday",    tDAY, 3 },
  1361.     { "wednes",        tDAY, 3 },
  1362.     { "thursday",    tDAY, 4 },
  1363.     { "thur",        tDAY, 4 },
  1364.     { "thurs",        tDAY, 4 },
  1365.     { "friday",        tDAY, 5 },
  1366.     { "saturday",    tDAY, 6 },
  1367.     { NULL }
  1368. };
  1369.  
  1370. /* Time units table. */
  1371. static TABLE const UnitsTable[] = {
  1372.     { "year",        tMONTH_UNIT,    12 },
  1373.     { "month",        tMONTH_UNIT,    1 },
  1374.     { "fortnight",    tMINUTE_UNIT,    14 * 24 * 60 },
  1375.     { "week",        tMINUTE_UNIT,    7 * 24 * 60 },
  1376.     { "day",        tMINUTE_UNIT,    1 * 24 * 60 },
  1377.     { "hour",        tMINUTE_UNIT,    60 },
  1378.     { "minute",        tMINUTE_UNIT,    1 },
  1379.     { "min",        tMINUTE_UNIT,    1 },
  1380.     { "second",        tSEC_UNIT,    1 },
  1381.     { "sec",        tSEC_UNIT,    1 },
  1382.     { NULL }
  1383. };
  1384.  
  1385. /* Assorted relative-time words. */
  1386. static TABLE const OtherTable[] = {
  1387.     { "tomorrow",    tMINUTE_UNIT,    1 * 24 * 60 },
  1388.     { "yesterday",    tMINUTE_UNIT,    -1 * 24 * 60 },
  1389.     { "today",        tMINUTE_UNIT,    0 },
  1390.     { "now",        tMINUTE_UNIT,    0 },
  1391.     { "last",        tUNUMBER,    -1 },
  1392.     { "this",        tMINUTE_UNIT,    0 },
  1393.     { "next",        tUNUMBER,    2 },
  1394.     { "first",        tUNUMBER,    1 },
  1395. /*  { "second",        tUNUMBER,    2 }, */
  1396.     { "third",        tUNUMBER,    3 },
  1397.     { "fourth",        tUNUMBER,    4 },
  1398.     { "fifth",        tUNUMBER,    5 },
  1399.     { "sixth",        tUNUMBER,    6 },
  1400.     { "seventh",    tUNUMBER,    7 },
  1401.     { "eighth",        tUNUMBER,    8 },
  1402.     { "ninth",        tUNUMBER,    9 },
  1403.     { "tenth",        tUNUMBER,    10 },
  1404.     { "eleventh",    tUNUMBER,    11 },
  1405.     { "twelfth",    tUNUMBER,    12 },
  1406.     { "ago",        tAGO,    1 },
  1407.     { NULL }
  1408. };
  1409.  
  1410. /* The timezone table. */
  1411. /* Some of these are commented out because a time_t can't store a float. */
  1412. static TABLE const TimezoneTable[] = {
  1413.     { "gmt",    tZONE,     HOUR( 0) },    /* Greenwich Mean */
  1414.     { "ut",    tZONE,     HOUR( 0) },    /* Universal (Coordinated) */
  1415.     { "utc",    tZONE,     HOUR( 0) },
  1416.     { "wet",    tZONE,     HOUR( 0) },    /* Western European */
  1417.     { "bst",    tDAYZONE,  HOUR( 0) },    /* British Summer */
  1418.     { "wat",    tZONE,     HOUR( 1) },    /* West Africa */
  1419.     { "at",    tZONE,     HOUR( 2) },    /* Azores */
  1420. #if    0
  1421.     /* For completeness.  BST is also British Summer, and GST is
  1422.      * also Guam Standard. */
  1423.     { "bst",    tZONE,     HOUR( 3) },    /* Brazil Standard */
  1424.     { "gst",    tZONE,     HOUR( 3) },    /* Greenland Standard */
  1425. #endif
  1426. #if 0
  1427.     { "nft",    tZONE,     HOUR(3.5) },    /* Newfoundland */
  1428.     { "nst",    tZONE,     HOUR(3.5) },    /* Newfoundland Standard */
  1429.     { "ndt",    tDAYZONE,  HOUR(3.5) },    /* Newfoundland Daylight */
  1430. #endif
  1431.     { "ast",    tZONE,     HOUR( 4) },    /* Atlantic Standard */
  1432.     { "adt",    tDAYZONE,  HOUR( 4) },    /* Atlantic Daylight */
  1433.     { "est",    tZONE,     HOUR( 5) },    /* Eastern Standard */
  1434.     { "edt",    tDAYZONE,  HOUR( 5) },    /* Eastern Daylight */
  1435.     { "cst",    tZONE,     HOUR( 6) },    /* Central Standard */
  1436.     { "cdt",    tDAYZONE,  HOUR( 6) },    /* Central Daylight */
  1437.     { "mst",    tZONE,     HOUR( 7) },    /* Mountain Standard */
  1438.     { "mdt",    tDAYZONE,  HOUR( 7) },    /* Mountain Daylight */
  1439.     { "pst",    tZONE,     HOUR( 8) },    /* Pacific Standard */
  1440.     { "pdt",    tDAYZONE,  HOUR( 8) },    /* Pacific Daylight */
  1441.     { "yst",    tZONE,     HOUR( 9) },    /* Yukon Standard */
  1442.     { "ydt",    tDAYZONE,  HOUR( 9) },    /* Yukon Daylight */
  1443.     { "hst",    tZONE,     HOUR(10) },    /* Hawaii Standard */
  1444.     { "hdt",    tDAYZONE,  HOUR(10) },    /* Hawaii Daylight */
  1445.     { "cat",    tZONE,     HOUR(10) },    /* Central Alaska */
  1446.     { "ahst",    tZONE,     HOUR(10) },    /* Alaska-Hawaii Standard */
  1447.     { "nt",    tZONE,     HOUR(11) },    /* Nome */
  1448.     { "idlw",    tZONE,     HOUR(12) },    /* International Date Line West */
  1449.     { "cet",    tZONE,     -HOUR(1) },    /* Central European */
  1450.     { "met",    tZONE,     -HOUR(1) },    /* Middle European */
  1451.     { "mewt",    tZONE,     -HOUR(1) },    /* Middle European Winter */
  1452.     { "mest",    tDAYZONE,  -HOUR(1) },    /* Middle European Summer */
  1453.     { "swt",    tZONE,     -HOUR(1) },    /* Swedish Winter */
  1454.     { "sst",    tDAYZONE,  -HOUR(1) },    /* Swedish Summer */
  1455.     { "fwt",    tZONE,     -HOUR(1) },    /* French Winter */
  1456.     { "fst",    tDAYZONE,  -HOUR(1) },    /* French Summer */
  1457.     { "eet",    tZONE,     -HOUR(2) },    /* Eastern Europe, USSR Zone 1 */
  1458.     { "bt",    tZONE,     -HOUR(3) },    /* Baghdad, USSR Zone 2 */
  1459. #if 0
  1460.     { "it",    tZONE,     -HOUR(3.5) },/* Iran */
  1461. #endif
  1462.     { "zp4",    tZONE,     -HOUR(4) },    /* USSR Zone 3 */
  1463.     { "zp5",    tZONE,     -HOUR(5) },    /* USSR Zone 4 */
  1464. #if 0
  1465.     { "ist",    tZONE,     -HOUR(5.5) },/* Indian Standard */
  1466. #endif
  1467.     { "zp6",    tZONE,     -HOUR(6) },    /* USSR Zone 5 */
  1468. #if    0
  1469.     /* For completeness.  NST is also Newfoundland Stanard, and SST is
  1470.      * also Swedish Summer. */
  1471.     { "nst",    tZONE,     -HOUR(6.5) },/* North Sumatra */
  1472.     { "sst",    tZONE,     -HOUR(7) },    /* South Sumatra, USSR Zone 6 */
  1473. #endif    /* 0 */
  1474.     { "wast",    tZONE,     -HOUR(7) },    /* West Australian Standard */
  1475.     { "wadt",    tDAYZONE,  -HOUR(7) },    /* West Australian Daylight */
  1476. #if 0
  1477.     { "jt",    tZONE,     -HOUR(7.5) },/* Java (3pm in Cronusland!) */
  1478. #endif
  1479.     { "cct",    tZONE,     -HOUR(8) },    /* China Coast, USSR Zone 7 */
  1480.     { "jst",    tZONE,     -HOUR(9) },    /* Japan Standard, USSR Zone 8 */
  1481. #if 0
  1482.     { "cast",    tZONE,     -HOUR(9.5) },/* Central Australian Standard */
  1483.     { "cadt",    tDAYZONE,  -HOUR(9.5) },/* Central Australian Daylight */
  1484. #endif
  1485.     { "east",    tZONE,     -HOUR(10) },    /* Eastern Australian Standard */
  1486.     { "eadt",    tDAYZONE,  -HOUR(10) },    /* Eastern Australian Daylight */
  1487.     { "gst",    tZONE,     -HOUR(10) },    /* Guam Standard, USSR Zone 9 */
  1488.     { "nzt",    tZONE,     -HOUR(12) },    /* New Zealand */
  1489.     { "nzst",    tZONE,     -HOUR(12) },    /* New Zealand Standard */
  1490.     { "nzdt",    tDAYZONE,  -HOUR(12) },    /* New Zealand Daylight */
  1491.     { "idle",    tZONE,     -HOUR(12) },    /* International Date Line East */
  1492.     {  NULL  }
  1493. };
  1494.  
  1495. /* Military timezone table. */
  1496. static TABLE const MilitaryTable[] = {
  1497.     { "a",    tZONE,    HOUR(  1) },
  1498.     { "b",    tZONE,    HOUR(  2) },
  1499.     { "c",    tZONE,    HOUR(  3) },
  1500.     { "d",    tZONE,    HOUR(  4) },
  1501.     { "e",    tZONE,    HOUR(  5) },
  1502.     { "f",    tZONE,    HOUR(  6) },
  1503.     { "g",    tZONE,    HOUR(  7) },
  1504.     { "h",    tZONE,    HOUR(  8) },
  1505.     { "i",    tZONE,    HOUR(  9) },
  1506.     { "k",    tZONE,    HOUR( 10) },
  1507.     { "l",    tZONE,    HOUR( 11) },
  1508.     { "m",    tZONE,    HOUR( 12) },
  1509.     { "n",    tZONE,    HOUR(- 1) },
  1510.     { "o",    tZONE,    HOUR(- 2) },
  1511.     { "p",    tZONE,    HOUR(- 3) },
  1512.     { "q",    tZONE,    HOUR(- 4) },
  1513.     { "r",    tZONE,    HOUR(- 5) },
  1514.     { "s",    tZONE,    HOUR(- 6) },
  1515.     { "t",    tZONE,    HOUR(- 7) },
  1516.     { "u",    tZONE,    HOUR(- 8) },
  1517.     { "v",    tZONE,    HOUR(- 9) },
  1518.     { "w",    tZONE,    HOUR(-10) },
  1519.     { "x",    tZONE,    HOUR(-11) },
  1520.     { "y",    tZONE,    HOUR(-12) },
  1521.     { "z",    tZONE,    HOUR(  0) },
  1522.     { NULL }
  1523. };
  1524.  
  1525.  
  1526.  
  1527.  
  1528. /* ARGSUSED */
  1529. static int
  1530. yyerror(s)
  1531.     char    *s;
  1532. {
  1533.   return 0;
  1534. }
  1535.  
  1536.  
  1537. static time_t
  1538. ToSeconds(Hours, Minutes, Seconds, Meridian)
  1539.     time_t    Hours;
  1540.     time_t    Minutes;
  1541.     time_t    Seconds;
  1542.     MERIDIAN    Meridian;
  1543. {
  1544.     if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
  1545.     return -1;
  1546.     switch (Meridian) {
  1547.     case MER24:
  1548.     if (Hours < 0 || Hours > 23)
  1549.         return -1;
  1550.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1551.     case MERam:
  1552.     if (Hours < 1 || Hours > 12)
  1553.         return -1;
  1554.     return (Hours * 60L + Minutes) * 60L + Seconds;
  1555.     case MERpm:
  1556.     if (Hours < 1 || Hours > 12)
  1557.         return -1;
  1558.     return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
  1559.     default:
  1560.     abort ();
  1561.     }
  1562.     /* NOTREACHED */
  1563. }
  1564.  
  1565.  
  1566. static time_t
  1567. Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
  1568.     time_t    Month;
  1569.     time_t    Day;
  1570.     time_t    Year;
  1571.     time_t    Hours;
  1572.     time_t    Minutes;
  1573.     time_t    Seconds;
  1574.     MERIDIAN    Meridian;
  1575.     DSTMODE    DSTmode;
  1576. {
  1577.     static int DaysInMonth[12] = {
  1578.     31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  1579.     };
  1580.     time_t    tod;
  1581.     time_t    Julian;
  1582.     int        i;
  1583.  
  1584.     if (Year < 0)
  1585.     Year = -Year;
  1586.     if (Year < 100)
  1587.     Year += 1900;
  1588.     DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
  1589.             ? 29 : 28;
  1590.     if (Year < EPOCH || Year > 1999
  1591.      || Month < 1 || Month > 12
  1592.      /* Lint fluff:  "conversion from long may lose accuracy" */
  1593.      || Day < 1 || Day > DaysInMonth[(int)--Month])
  1594.     return -1;
  1595.  
  1596.     for (Julian = Day - 1, i = 0; i < Month; i++)
  1597.     Julian += DaysInMonth[i];
  1598.     for (i = EPOCH; i < Year; i++)
  1599.     Julian += 365 + (i % 4 == 0);
  1600.     Julian *= SECSPERDAY;
  1601.     Julian += yyTimezone * 60L;
  1602.     if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
  1603.     return -1;
  1604.     Julian += tod;
  1605.     if (DSTmode == DSTon
  1606.      || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
  1607.     Julian -= 60 * 60;
  1608.     return Julian;
  1609. }
  1610.  
  1611.  
  1612. static time_t
  1613. DSTcorrect(Start, Future)
  1614.     time_t    Start;
  1615.     time_t    Future;
  1616. {
  1617.     time_t    StartDay;
  1618.     time_t    FutureDay;
  1619.  
  1620.     StartDay = (localtime(&Start)->tm_hour + 1) % 24;
  1621.     FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
  1622.     return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
  1623. }
  1624.  
  1625.  
  1626. static time_t
  1627. RelativeDate(Start, DayOrdinal, DayNumber)
  1628.     time_t    Start;
  1629.     time_t    DayOrdinal;
  1630.     time_t    DayNumber;
  1631. {
  1632.     struct tm    *tm;
  1633.     time_t    now;
  1634.  
  1635.     now = Start;
  1636.     tm = localtime(&now);
  1637.     now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
  1638.     now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
  1639.     return DSTcorrect(Start, now);
  1640. }
  1641.  
  1642.  
  1643. static time_t
  1644. RelativeMonth(Start, RelMonth)
  1645.     time_t    Start;
  1646.     time_t    RelMonth;
  1647. {
  1648.     struct tm    *tm;
  1649.     time_t    Month;
  1650.     time_t    Year;
  1651.  
  1652.     if (RelMonth == 0)
  1653.     return 0;
  1654.     tm = localtime(&Start);
  1655.     Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
  1656.     Year = Month / 12;
  1657.     Month = Month % 12 + 1;
  1658.     return DSTcorrect(Start,
  1659.         Convert(Month, (time_t)tm->tm_mday, Year,
  1660.         (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
  1661.         MER24, DSTmaybe));
  1662. }
  1663.  
  1664.  
  1665. static int
  1666. LookupWord(buff)
  1667.     char        *buff;
  1668. {
  1669.     register char    *p;
  1670.     register char    *q;
  1671.     register const TABLE    *tp;
  1672.     int            i;
  1673.     int            abbrev;
  1674.  
  1675.     /* Make it lowercase. */
  1676.     for (p = buff; *p; p++)
  1677.     if (isupper(*p))
  1678.         *p = tolower(*p);
  1679.  
  1680.     if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
  1681.     yylval.Meridian = MERam;
  1682.     return tMERIDIAN;
  1683.     }
  1684.     if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
  1685.     yylval.Meridian = MERpm;
  1686.     return tMERIDIAN;
  1687.     }
  1688.  
  1689.     /* See if we have an abbreviation for a month. */
  1690.     if (strlen(buff) == 3)
  1691.     abbrev = 1;
  1692.     else if (strlen(buff) == 4 && buff[3] == '.') {
  1693.     abbrev = 1;
  1694.     buff[3] = '\0';
  1695.     }
  1696.     else
  1697.     abbrev = 0;
  1698.  
  1699.     for (tp = MonthDayTable; tp->name; tp++) {
  1700.     if (abbrev) {
  1701.         if (strncmp(buff, tp->name, 3) == 0) {
  1702.         yylval.Number = tp->value;
  1703.         return tp->type;
  1704.         }
  1705.     }
  1706.     else if (strcmp(buff, tp->name) == 0) {
  1707.         yylval.Number = tp->value;
  1708.         return tp->type;
  1709.     }
  1710.     }
  1711.  
  1712.     for (tp = TimezoneTable; tp->name; tp++)
  1713.     if (strcmp(buff, tp->name) == 0) {
  1714.         yylval.Number = tp->value;
  1715.         return tp->type;
  1716.     }
  1717.  
  1718.     if (strcmp(buff, "dst") == 0) 
  1719.     return tDST;
  1720.  
  1721.     for (tp = UnitsTable; tp->name; tp++)
  1722.     if (strcmp(buff, tp->name) == 0) {
  1723.         yylval.Number = tp->value;
  1724.         return tp->type;
  1725.     }
  1726.  
  1727.     /* Strip off any plural and try the units table again. */
  1728.     i = strlen(buff) - 1;
  1729.     if (buff[i] == 's') {
  1730.     buff[i] = '\0';
  1731.     for (tp = UnitsTable; tp->name; tp++)
  1732.         if (strcmp(buff, tp->name) == 0) {
  1733.         yylval.Number = tp->value;
  1734.         return tp->type;
  1735.         }
  1736.     buff[i] = 's';        /* Put back for "this" in OtherTable. */
  1737.     }
  1738.  
  1739.     for (tp = OtherTable; tp->name; tp++)
  1740.     if (strcmp(buff, tp->name) == 0) {
  1741.         yylval.Number = tp->value;
  1742.         return tp->type;
  1743.     }
  1744.  
  1745.     /* Military timezones. */
  1746.     if (buff[1] == '\0' && isalpha(*buff)) {
  1747.     for (tp = MilitaryTable; tp->name; tp++)
  1748.         if (strcmp(buff, tp->name) == 0) {
  1749.         yylval.Number = tp->value;
  1750.         return tp->type;
  1751.         }
  1752.     }
  1753.  
  1754.     /* Drop out any periods and try the timezone table again. */
  1755.     for (i = 0, p = q = buff; *q; q++)
  1756.     if (*q != '.')
  1757.         *p++ = *q;
  1758.     else
  1759.         i++;
  1760.     *p = '\0';
  1761.     if (i)
  1762.     for (tp = TimezoneTable; tp->name; tp++)
  1763.         if (strcmp(buff, tp->name) == 0) {
  1764.         yylval.Number = tp->value;
  1765.         return tp->type;
  1766.         }
  1767.  
  1768.     return tID;
  1769. }
  1770.  
  1771.  
  1772. static int
  1773. yylex()
  1774. {
  1775.     register char    c;
  1776.     register char    *p;
  1777.     char        buff[20];
  1778.     int            Count;
  1779.     int            sign;
  1780.  
  1781.     for ( ; ; ) {
  1782.     while (isspace(*yyInput))
  1783.         yyInput++;
  1784.  
  1785.     if (isdigit(c = *yyInput) || c == '-' || c == '+') {
  1786.         if (c == '-' || c == '+') {
  1787.         sign = c == '-' ? -1 : 1;
  1788.         if (!isdigit(*++yyInput))
  1789.             /* skip the '-' sign */
  1790.             continue;
  1791.         }
  1792.         else
  1793.         sign = 0;
  1794.         for (yylval.Number = 0; isdigit(c = *yyInput++); )
  1795.         yylval.Number = 10 * yylval.Number + c - '0';
  1796.         yyInput--;
  1797.         if (sign < 0)
  1798.         yylval.Number = -yylval.Number;
  1799.         return sign ? tSNUMBER : tUNUMBER;
  1800.     }
  1801.     if (isalpha(c)) {
  1802.         for (p = buff; isalpha(c = *yyInput++) || c == '.'; )
  1803.         if (p < &buff[sizeof buff - 1])
  1804.             *p++ = c;
  1805.         *p = '\0';
  1806.         yyInput--;
  1807.         return LookupWord(buff);
  1808.     }
  1809.     if (c != '(')
  1810.         return *yyInput++;
  1811.     Count = 0;
  1812.     do {
  1813.         c = *yyInput++;
  1814.         if (c == '\0')
  1815.         return c;
  1816.         if (c == '(')
  1817.         Count++;
  1818.         else if (c == ')')
  1819.         Count--;
  1820.     } while (Count > 0);
  1821.     }
  1822. }
  1823.  
  1824.  
  1825. #define TM_YEAR_ORIGIN 1900
  1826.  
  1827. /* Yield A - B, measured in seconds.  */
  1828. static time_t
  1829. difftm(a, b)
  1830.      struct tm *a, *b;
  1831. {
  1832.   int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
  1833.   int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
  1834.   return
  1835.     (
  1836.      (
  1837.       (
  1838.        /* difference in day of year */
  1839.        a->tm_yday - b->tm_yday
  1840.        /* + intervening leap days */
  1841.        +  ((ay >> 2) - (by >> 2))
  1842.        -  (ay/100 - by/100)
  1843.        +  ((ay/100 >> 2) - (by/100 >> 2))
  1844.        /* + difference in years * 365 */
  1845.        +  (time_t)(ay-by) * 365
  1846.        )*24 + (a->tm_hour - b->tm_hour)
  1847.       )*60 + (a->tm_min - b->tm_min)
  1848.      )*60 + (a->tm_sec - b->tm_sec);
  1849. }
  1850.  
  1851. time_t
  1852. get_date(p, now)
  1853.     char        *p;
  1854.     struct timeb    *now;
  1855. {
  1856.     struct tm        *tm, gmt;
  1857.     struct timeb    ftz;
  1858.     time_t        Start;
  1859.     time_t        tod;
  1860.  
  1861.     yyInput = p;
  1862.     if (now == NULL) {
  1863.         now = &ftz;
  1864.     (void)time(&ftz.time);
  1865.  
  1866.     if (! (tm = gmtime (&ftz.time)))
  1867.         return -1;
  1868.     gmt = *tm;    /* Make a copy, in case localtime modifies *tm.  */
  1869.     ftz.timezone = difftm (&gmt, localtime (&ftz.time)) / 60;
  1870.     }
  1871.  
  1872.     tm = localtime(&now->time);
  1873.     yyYear = tm->tm_year;
  1874.     yyMonth = tm->tm_mon + 1;
  1875.     yyDay = tm->tm_mday;
  1876.     yyTimezone = now->timezone;
  1877.     yyDSTmode = DSTmaybe;
  1878.     yyHour = 0;
  1879.     yyMinutes = 0;
  1880.     yySeconds = 0;
  1881.     yyMeridian = MER24;
  1882.     yyRelSeconds = 0;
  1883.     yyRelMonth = 0;
  1884.     yyHaveDate = 0;
  1885.     yyHaveDay = 0;
  1886.     yyHaveRel = 0;
  1887.     yyHaveTime = 0;
  1888.     yyHaveZone = 0;
  1889.  
  1890.     if (yyparse()
  1891.      || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
  1892.     return -1;
  1893.  
  1894.     if (yyHaveDate || yyHaveTime || yyHaveDay) {
  1895.     Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
  1896.             yyMeridian, yyDSTmode);
  1897.     if (Start < 0)
  1898.         return -1;
  1899.     }
  1900.     else {
  1901.     Start = now->time;
  1902.     if (!yyHaveRel)
  1903.         Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec;
  1904.     }
  1905.  
  1906.     Start += yyRelSeconds;
  1907.     Start += RelativeMonth(Start, yyRelMonth);
  1908.  
  1909.     if (yyHaveDay && !yyHaveDate) {
  1910.     tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
  1911.     Start += tod;
  1912.     }
  1913.  
  1914.     /* Have to do *something* with a legitimate -1 so it's distinguishable
  1915.      * from the error return value.  (Alternately could set errno on error.) */
  1916.     return Start == -1 ? 0 : Start;
  1917. }
  1918.  
  1919.  
  1920. #if    defined(TEST)
  1921.  
  1922. /* ARGSUSED */
  1923. main(ac, av)
  1924.     int        ac;
  1925.     char    *av[];
  1926. {
  1927.     char    buff[128];
  1928.     time_t    d;
  1929.  
  1930.     (void)printf("Enter date, or blank line to exit.\n\t> ");
  1931.     (void)fflush(stdout);
  1932.     while (gets(buff) && buff[0]) {
  1933.     d = get_date(buff, (struct timeb *)NULL);
  1934.     if (d == -1)
  1935.         (void)printf("Bad format - couldn't convert.\n");
  1936.     else
  1937.         (void)printf("%s", ctime(&d));
  1938.     (void)printf("\t> ");
  1939.     (void)fflush(stdout);
  1940.     }
  1941.     exit(0);
  1942.     /* NOTREACHED */
  1943. }
  1944. #endif    /* defined(TEST) */
  1945.